package com.shengdai.urms.core.model;

import java.util.Calendar;


/**
 * 登录信息对象
 *
 */
public class UmLogon implements java.io.Serializable {
	private static final long	serialVersionUID	= 30014016L;
	public static final String	LOGONVO				= "LOGONVO";
	public static final String	LOGONVO_LOGINFROM_I	= "I";
	public static final String	LOGONVO_LOGINFROM_O	= "O";
	public static final String	F_LANMASK			= "LAN_MASK";
	private String				sessionid;							// 登录会话ID
	private String				userid;
	private String				logonid;
	private String				orgid;								// 组织id
	private String				password;
	private String				username;
	private String				parentids;
	private String				parentnames;
	private String				parenttypes;
	private Calendar			deadline;
	private boolean				spuser;
	private boolean				outofdate;
	private String				currsys;
	private String				framesetid;						// 用户门户ID
	private String				template;
	private String				stylecode;
	private String				loginfrom;							// 访问来源，识别内外网标识
	private String				loginhost;							// 登录主机
	private String				loginip;							// 登录ip地址
	private String				mulriple;
	private Calendar			createdate;						// 登录时间
	private String				logintype;							// 登录类型 唯一登录,多窗口登录,多IP登录
	private String				ukeyenabled;						// ukey是否可用 Y-是，N-否。如果可用，则此用户必须用ukey登录；否则只能用帐号密码登录。
	private boolean				frozen				= false;
	private Calendar			freezetime;						// 账号被冻结的时间
	private Calendar			lastlogin;							// 最近一次登陆日期
	private Calendar			pwdupdate;							// 密码上次更新时间
	private String				status;							// 是否离职标志 (0.离职 1.在职 2.停职 3.冻结)
	private Integer				logintimes;							//  登录系统次数
	private String				shortcuttype;						//快捷菜单显示类型
	private Integer				shortcutviewnum;					//快捷菜单显示条数

	public String getShortcuttype() {
		return shortcuttype;
	}

	public void setShortcuttype(String shortcuttype) {
		this.shortcuttype = shortcuttype;
	}

	public Integer getShortcutviewnum() {
		return shortcutviewnum;
	}

	public void setShortcutviewnum(Integer shortcutviewnum) {
		this.shortcutviewnum = shortcutviewnum;
	}

	public Integer getLogintimes() {
		return logintimes;
	}

	public void setLogintimes(Integer logintimes) {
		this.logintimes = logintimes;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getLoginhost() {
		return loginhost;
	}

	public void setLoginhost(String loginhost) {
		this.loginhost = loginhost;
	}

	public String getLoginip() {
		return loginip;
	}

	public void setLoginip(String loginip) {
		this.loginip = loginip;
	}

	public String getLoginfrom() {
		return loginfrom;
	}

	public void setLoginfrom(String loginfrom) {
		this.loginfrom = loginfrom;
	}

	public String getStylecode() {
		return stylecode;
	}

	public void setStylecode(String stylecode) {
		this.stylecode = stylecode;
	}

	public String getTemplate() {
		return template;
	}

	public void setTemplate(String template) {
		this.template = template;
	}

	public boolean isOutofdate() {
		return outofdate;
	}

	public void setOutofdate(boolean outofdate) {
		this.outofdate = outofdate;
	}

	public UmLogon() {

	}


	public UmLogon(UmSpuser usr) {
		this.userid = usr.getSpuserid();
		this.username = usr.getSpusername();
		this.logonid = usr.getLogonid();
		this.deadline = usr.getAge();
		this.outofdate = this.deadline != null ? this.deadline.before(Calendar.getInstance()) : false;
		this.framesetid = usr.getFramesetid();
		this.password = usr.getPassword();
		this.spuser = true;
		this.createdate = Calendar.getInstance();
		this.frozen="TY".equals(usr.getStatus());
		this.logintimes = Integer.valueOf(10000);//超级用户登录次数永远固定为10000
	}

	public UmLogon(UmUser usr) {
		this.userid = usr.getUserid();
		this.username = usr.getUsername();
		this.logonid = usr.getLogonid();
		this.orgid = usr.getOrgid();
		this.parentids = usr.getParentids();
		this.parentnames = usr.getParentnames();
		this.parenttypes = usr.getParenttypes();
		this.deadline = usr.getAge();
		this.outofdate = this.deadline != null ? this.deadline.before(Calendar.getInstance()) : false;
		this.spuser = false;
		this.password = usr.getPassword();
		this.mulriple = usr.getMulriple();
		this.createdate = Calendar.getInstance();
		this.logintype = usr.getLogintype();
		this.ukeyenabled = usr.getUkeyenabled();
		this.frozen = "3".equals(usr.getStatus());
		this.lastlogin = usr.getLastlogin();
		this.pwdupdate = usr.getPwdupdate();
		this.status = usr.getStatus();
		this.freezetime = usr.getFreezetime();
		this.logintimes = usr.getLogintimes();
		this.shortcuttype = usr.getShortcuttype();
		this.shortcutviewnum = usr.getShortcutviewnum();
	}

	public String getParentids() {
		return parentids;
	}

	public void setParentids(String parentids) {
		this.parentids = parentids;
	}

	public String getParentnames() {
		return parentnames;
	}

	public void setParentnames(String parentnames) {
		this.parentnames = parentnames;
	}

	public boolean isSpuser() {
		return spuser;
	}

	public void setSpuser(boolean spuser) {
		this.spuser = spuser;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getLogonid() {
		return logonid;
	}

	public void setLogonid(String logonid) {
		this.logonid = logonid;
	}

	public String getUserid() {
		return userid;
	}

	public void setUserid(String userid) {
		this.userid = userid;
	}

	public String getCurrsys() {
		return currsys;
	}

	public void setCurrsys(String currsys) {
		this.currsys = currsys;
	}

	public String getFramesetid() {
		return framesetid;
	}

	public void setFramesetid(String framesetid) {
		this.framesetid = framesetid;
	}

	public String getSessionid() {
		return sessionid;
	}

	public void setSessionid(String sessionid) {
		this.sessionid = sessionid;
	}

	/**
	 * 返回本组织名称。本公司、本部门、本单位等
	 *
	 * @param cfgvalue
	 *            本组织的配置码
	 * @return
	 */
	public String getSelfOrgname(String cfgvalue) {
		if (cfgvalue == null || cfgvalue.length() == 0) {
			// System.out.println("父组织配置规则错误，请检查：" + cfgvalue);
			return null;
		}

		if (parentnames == null || parentnames.length() == 0) {
			// if (spuser == false)
			// System.out.println("父组织名称为空，请检查。");
			return null;
		}

		// 考虑父组织id保存不标准情况
		if (parentnames.startsWith("-"))
			parentnames = parentnames.substring(1);

		if (parentnames.endsWith("-"))
			parentnames = parentnames.substring(0, parentids.length() - 1);

		// 检查父组织是否正确
		String[] names = parentnames.split("-");

		// 规则解释 层级从1开始，+表示从顶开始，-表示从低开始，+2表示从顶开始第二层
		String orgid = null;

		if (cfgvalue.startsWith("-")) {
			String lev = cfgvalue.substring(1);
			int ilev = Integer.parseInt(lev);
			if (ilev < 0)
				ilev = 0;
			else if (ilev > names.length - 1)
				ilev = names.length - 1;

			orgid = names[names.length - ilev];
		} else if (cfgvalue.startsWith("+")) {
			String lev = cfgvalue.substring(1);
			int ilev = Integer.parseInt(lev);
			if (ilev < 0)
				ilev = 0;
			else if (ilev > names.length - 1)
				ilev = names.length - 1;
			orgid = names[ilev];
		} else {
			int ilev = Integer.parseInt(cfgvalue);
			if (ilev < 0)
				ilev = 0;
			else if (ilev > names.length - 1)
				ilev = names.length - 1;
			orgid = names[ilev];
		}
		return orgid;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	/**
	 * 返回本组织编码
	 *
	 * @param cfgvalue
	 * @return
	 */
	public String getSelfOrgid(String cfgvalue) {
		if (cfgvalue == null || cfgvalue.length() == 0) {
			// System.out.println("父组织配置规则错误，请检查：" + cfgvalue);
			return null;
		}

		if (parentids == null || parentids.length() == 0) {
			// if (spuser == false)
			// System.out.println("父组织ID为空，请检查。");
			return null;
		}

		// 考虑父组织id保存不标准情况
		if (parentids.startsWith(","))
			parentids = parentids.substring(1);

		if (parentids.endsWith(","))
			parentids = parentids.substring(0, parentids.length() - 1);

		// 检查父组织是否正确
		String[] ids = parentids.split(",");

		// 规则解释 层级从1开始，+表示从顶开始，-表示从低开始，+2表示从顶开始第二层
		String orgid = null;

		if (cfgvalue.startsWith("-")) {
			String lev = cfgvalue.substring(1);
			int ilev = Integer.parseInt(lev);
			if (ilev < 1)
				ilev = 1;
			else if (ilev > ids.length - 1)
				ilev = ids.length - 1;

			orgid = ids[ids.length - ilev];
		} else if (cfgvalue.startsWith("+")) {
			String lev = cfgvalue.substring(1);
			int ilev = Integer.parseInt(lev);
			if (ilev < 1)
				ilev = 1;
			else if (ilev > ids.length - 1)
				ilev = ids.length - 1;
			orgid = ids[ilev];
		} else {
			int ilev = Integer.parseInt(cfgvalue);
			if (ilev < 1)
				ilev = 1;
			else if (ilev > ids.length - 1)
				ilev = ids.length - 1;
			orgid = ids[ilev];
		}
		return orgid;

	}

	public String getMulriple() {
		return mulriple;
	}

	public void setMulriple(String mulriple) {
		this.mulriple = mulriple;
	}

	public String getParenttypes() {
		return parenttypes;
	}

	public void setParenttypes(String parenttypes) {
		this.parenttypes = parenttypes;
	}

	public String getOrgid() {
		return orgid;
	}

	public void setOrgid(String orgid) {
		this.orgid = orgid;
	}

	public String getLogintype() {
		return logintype;
	}

	public void setLogintype(String logintype) {
		this.logintype = logintype;
	}

	public String getUkeyenabled() {
		return ukeyenabled;
	}

	public void setUkeyenabled(String ukeyenabled) {
		this.ukeyenabled = ukeyenabled;
	}

	public boolean isFrozen() {
		return frozen;
	}

	public void setFrozen(boolean frozen) {
		this.frozen = frozen;
	}

	public Calendar getDeadline() {
		return deadline;
	}

	public void setDeadline(Calendar deadline) {
		this.deadline = deadline;
	}

	public Calendar getCreatedate() {
		return createdate;
	}

	public void setCreatedate(Calendar createdate) {
		this.createdate = createdate;
	}

	public Calendar getFreezetime() {
		return freezetime;
	}

	public void setFreezetime(Calendar freezetime) {
		this.freezetime = freezetime;
	}

	public Calendar getLastlogin() {
		return lastlogin;
	}

	public void setLastlogin(Calendar lastlogin) {
		this.lastlogin = lastlogin;
	}

	public Calendar getPwdupdate() {
		return pwdupdate;
	}

	public void setPwdupdate(Calendar pwdupdate) {
		this.pwdupdate = pwdupdate;
	}

}
